pacman::p_load(sf,tidyverse,spNetwork,tmap,classInt, viridis)Take-home Exercise 3: NKDE
Packages
Import data
crime_data <- read_rds("../../data/proj_data/rds/accidents_thai.rds") %>%
st_transform(crs = 24047)
# thai_bound <- st_read(dsn = "../../data/proj_data/thai_adm_boundary",
# layer = "tha_admbnda_adm1_rtsd_20220121") %>%
# st_transform(crs = 24047)
thai_bound <- st_read(dsn = "../../data/proj_data/thai_adm_boundary",
layer = "tha_admbnda_adm2_rtsd_20220121") %>%
st_transform(crs = 24047)Reading layer `tha_admbnda_adm2_rtsd_20220121' from data source
`/Users/tangtang/Desktop/IS415 Geospatial Analytics and Applications/practice/is415gaa/data/proj_data/thai_adm_boundary'
using driver `ESRI Shapefile'
Simple feature collection with 928 features and 19 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 97.34336 ymin: 5.613038 xmax: 105.637 ymax: 20.46507
Geodetic CRS: WGS 84
thai_road <- read_rds("../../data/proj_data/rds/thai_roads.rds") %>%
st_transform(crs = 24047)Visualising difference in network constrained kernel density through different filters by columns
Some potential filtering to apply to dataset to allow user to zoom in into specific area he/she is interested in:
Accident categories
Fatal accident [yes/no]
Province (MUST-HAVE)
But let’s visualize the overall look
plot(crime_data)
Example: filter by province = “Bangkok”, accident_categories = “all”, fatal_accident == “all” (Allowing users to change freely)
Narrow down to city due to computation limitation
province_factor = "Bangkok"
crime_data_filtered = crime_data %>%
filter(province_en == province_factor)thai_prov <- thai_bound %>%
filter(ADM1_EN == province_factor)
tmap_mode("view")tmap mode set to interactive viewing
tm_shape(thai_prov) +
tm_polygons() +
tm_shape(crime_data_filtered) +
tm_dots(col = "black",
size = 0.01)